﻿/*
 *  创建者：    
 *      zlk
 *  创建时间：
 *      2011-7-20
 *  文件说明：
 *      弹出对话框的辅助类，基于ModualPopupExtender控件来完成，需要ScriptManager控件的配合
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using Sunimage.Spjg.Web.UserControls;

namespace Sunimage.Spjg.Web.Helper
{
    public class AlertHelper
    {
        /// <summary>
        /// 警告
        /// </summary>
        /// <param name="message"></param>
        /// <param name="page"></param>
        public static void ShowWarning(string message, Page page)
        {
            AlertMessage ucAlert = FindAlertUC(page);
            if (ucAlert != null)
                ucAlert.Warn(message);
        }

        /// <summary>
        /// 错误
        /// </summary>
        /// <param name="message"></param>
        /// <param name="page"></param>
        public static void ShowError(string message, Page page)
        {
            AlertMessage ucAlert = FindAlertUC(page);
            if (ucAlert != null)
                ucAlert.Error(message);
        }


        /// <summary>
        /// 提示
        /// </summary>
        /// <param name="message"></param>
        /// <param name="page"></param>
        public static void ShowMessage(string message, Page page)
        {
            AlertMessage ucAlert = FindAlertUC(page);
            if (ucAlert != null)
                ucAlert.Alert(message);
        }

        private static AlertMessage FindAlertUC(Page page)
        {
            object ctl = null;
            ctl = page.FindControl("ucAlertMessage");

            if (ctl == null)
            {
                if (page.Master != null)
                {
                    ctl = page.Master.FindControl("ucAlertMessage");
                    if (ctl == null)
                    {
                        if (page.Master.Master != null)
                        {
                            ctl = page.Master.Master.FindControl("ucAlertMessage");

                        }
                    }
                }
            }
            if (ctl != null)
            {
                AlertMessage ucAlert = ctl as AlertMessage;
                return ucAlert;
            }
            else
                return null;
        }
    }
}